import numpy as np
import torch.nn.functional as F
import cv2
import torchvision.transforms as transforms
from PIL import Image

img = cv2.imread("/media/hsmy/wanghao_18T/dataset/MIDOG2021/yolo_stain_aug_10x_1024/images/train/002_0_stain2.png")

transform = transforms.Compose([
    transforms.ToTensor(),
])
img = transform(img)
img = img.unsqueeze(0)

images_change = F.interpolate(img, size=(256, 256), mode='nearest')
print(images_change.shape)
images_change = images_change.squeeze(0)
images_change = images_change.permute(1, 2, 0)
img_array = images_change.cpu().numpy()
img = Image.fromarray((img_array * 255).astype(np.uint8))
img.save('resized_image.png')
